package com.cupk.rotaryguard.monitor.controller;

import com.cupk.common.base.utils.result.Result;
import com.cupk.rotaryguard.monitor.entity.DeviceInfo;
import com.cupk.rotaryguard.monitor.entity.vo.DeviceVo;
import com.cupk.rotaryguard.monitor.service.DeviceService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author tjy
 * @date 2023/3/26
 * @apiNote
 */
@RestController
@RequestMapping("/device")
public class DeviceManageController {

    @Resource
    private DeviceService deviceService;

    /**
     * 所有设备信息
     *
     * @return
     */
    @GetMapping("/list-all")
    public Result getDeviceInfo() {
        return deviceService.getDeviceInfo();
    }

    /**
     * 根据设备id获取设备数据
     *
     * @param id
     * @return
     */
    @GetMapping("/info/{id}")
    public Result getDeviceInfoById(@PathVariable Long id) {
        return deviceService.getDeviceInfoById(id);
    }

    /**
     * 根据型号、频率、功率查询设备状态
     *
     * @param deviceModel
     * @param deviceFrequency
     * @param devicePower
     * @param status
     * @return
     */
    @GetMapping("/list")
    public Result getDeviceInfoByParams(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String deviceModel,
            @RequestParam(defaultValue = "") BigDecimal deviceFrequency,
            @RequestParam(defaultValue = "") BigDecimal devicePower,
            @RequestParam(defaultValue = "") Integer status) {
        return deviceService.getDeviceInfoByParams(pageNum,pageSize,deviceModel, deviceFrequency, devicePower, status);
    }

    /**
     * 删除设备
     *
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public Result delDevices(@RequestBody List<Integer> ids) {
        return deviceService.delDevice(ids);
    }

    /**
     * 删除设备
     *
     * @param id
     * @return
     */
    @PostMapping("/del/{id}")
    public Result delDeviceById(@PathVariable Integer id) {
        return deviceService.delDeviceById(id);
    }

    /**
     * 添加设备
     *
     * @param deviceVo
     * @return
     */
    @PostMapping("/add")
    public Result addDevice(@RequestBody DeviceVo deviceVo) {
        return deviceService.addDevice(deviceVo);
    }

    /**
     * 更新设备信息
     *
     * @param id
     * @param deviceModel
     * @param deviceFrequency
     * @param devicePower
     * @return
     */
    @PostMapping("/ch")
    public Result chDeviceInfo(@RequestParam Long id,
                               @RequestParam String deviceModel,
                               @RequestParam BigDecimal deviceFrequency,
                               @RequestParam BigDecimal devicePower) {
        return deviceService.chDeviceInfo(id, deviceModel, deviceFrequency, devicePower);
    }

    /**
     * 获取运行中设备数量
     *
     * @return
     */
    @GetMapping("/running-count")
    public Result getRunningDeviceCount(){
        return deviceService.getRunningDeviceCount();
    }

    /**
     * 获取设备总数量
     *
     * @return
     */
    @GetMapping("/count")
    public Result getDeviceCount(){
        return deviceService.getDeviceCount();
    }


}
